/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.webapp.action;

import com.click.app.DateFormatChanger;
import com.click.app.model.PeriodPaymentEmployee;
import com.click.app.service.PeriodPaymentEmployeeManager;

/**
 *
 * @author ronald
 */
public class PeriodPaymentEmployeeAction extends BaseAction {
    
    private PeriodPaymentEmployee periodPaymentEmployee;
    private PeriodPaymentEmployeeManager periodPaymentEmployeeManager;
    private String endPeriodPaymentCut;
    private String endPeriodPaymentPant;

    public String closePeriodPaymentCut(){
        System.out.println("PeriodPaymentEmployeeAction -> closePeriodPaymentCut()");
        if(endPeriodPaymentCut != null){
            periodPaymentEmployee = periodPaymentEmployeeManager.get(periodPaymentEmployee.getId());
            periodPaymentEmployee.setEndDate(DateFormatChanger.changeStringtoDate(endPeriodPaymentCut));
            periodPaymentEmployee.setClosed(true);

            periodPaymentEmployee = periodPaymentEmployeeManager.save(periodPaymentEmployee);

            PeriodPaymentEmployee perPayEmpNew = new PeriodPaymentEmployee();
            perPayEmpNew.setInitAmount(periodPaymentEmployee.getCurrentAmount());
            perPayEmpNew.setCurrentAmount(periodPaymentEmployee.getCurrentAmount());
            perPayEmpNew.setDiscount(0.0D);
            perPayEmpNew.setInitDate(periodPaymentEmployee.getEndDate());
            perPayEmpNew.setClosed(false);
            perPayEmpNew.setAmountPayment(0.0D);
            perPayEmpNew.setAmountWon(0.0D);
            perPayEmpNew.setRole(periodPaymentEmployee.getRole());
            perPayEmpNew.setEmployee(periodPaymentEmployee.getEmployee());

            periodPaymentEmployeeManager.save(perPayEmpNew);

        }
        System.out.println("PeriodPaymentEmployeeAction -> end closePeriodPaymentCut()");
        return SUCCESS;
    }
    public String closePeriodPaymentPant(){
        System.out.println("PeriodPaymentEmployeeAction -> closePeriodPaymentPant()");
        if(endPeriodPaymentPant != null){
            periodPaymentEmployee = periodPaymentEmployeeManager.get(periodPaymentEmployee.getId());
            periodPaymentEmployee.setEndDate(DateFormatChanger.changeStringtoDate(endPeriodPaymentPant));
            periodPaymentEmployee.setClosed(true);

            periodPaymentEmployee = periodPaymentEmployeeManager.save(periodPaymentEmployee);

            PeriodPaymentEmployee perPayEmpNew = new PeriodPaymentEmployee();
            perPayEmpNew.setInitAmount(periodPaymentEmployee.getCurrentAmount());
            perPayEmpNew.setCurrentAmount(periodPaymentEmployee.getCurrentAmount());
            perPayEmpNew.setDiscount(0.0D);
            perPayEmpNew.setInitDate(periodPaymentEmployee.getEndDate());
            perPayEmpNew.setClosed(false);
            perPayEmpNew.setAmountPayment(0.0D);
            perPayEmpNew.setAmountWon(0.0D);
            perPayEmpNew.setRole(periodPaymentEmployee.getRole());
            perPayEmpNew.setEmployee(periodPaymentEmployee.getEmployee());

            periodPaymentEmployeeManager.save(perPayEmpNew);

        }
        System.out.println("PeriodPaymentEmployeeAction -> end closePeriodPaymentPant()");
        return SUCCESS;
    }


    public PeriodPaymentEmployee getPeriodPaymentEmployee() {
        return periodPaymentEmployee;
    }

    public void setPeriodPaymentEmployee(PeriodPaymentEmployee periodPaymentEmployee) {
        this.periodPaymentEmployee = periodPaymentEmployee;
    }

    public PeriodPaymentEmployeeManager getPeriodPaymentEmployeeManager() {
        return periodPaymentEmployeeManager;
    }

    public void setPeriodPaymentEmployeeManager(PeriodPaymentEmployeeManager periodPaymentEmployeeManager) {
        this.periodPaymentEmployeeManager = periodPaymentEmployeeManager;
    }

    public String getEndPeriodPaymentCut() {
        return endPeriodPaymentCut;
    }

    public void setEndPeriodPaymentCut(String endPeriodPaymentCut) {
        this.endPeriodPaymentCut = endPeriodPaymentCut;
    }

    public String getEndPeriodPaymentPant() {
        return endPeriodPaymentPant;
    }

    public void setEndPeriodPaymentPant(String endPeriodPaymentPant) {
        this.endPeriodPaymentPant = endPeriodPaymentPant;
    }
    


}
